// components/numCtrl/numCtrl.js
Component({
    /**
     * 组件的属性列表
     */
    properties: {
        count: {
            type: Number
        }
    },

    /**
     * 组件的初始数据
     */
    data: {
        count: 1 //用于表示当前数量
    },

    /**
     * 组件的方法列表
     */
    methods: {
        del() {
            let num = this.data.count;
            if (num > 1) {
                this.setData({
                    count: --num
                })
            } else {
                this.setData({
                    count: 1
                })
            }
        },
        add() {
            let num = this.data.count;
            if (num < 10) {
                this.setData({
                    count: ++num
                })
            } else {
                this.setData({
                    count: 10
                })
            }
            //发送数据  子组件向父组件传值
            this.sendCount();
        },
        del() {
            let num = this.data.count;
            if (num > 1) {
                this.setData({
                    count: --num
                })
            } else {
                this.setData({
                    count: 1
                })
            }
            //发送数据  子组件向父组件传值
            this.sendCount();
        },
        // 子组件向父组件传值
        sendCount(){
            let num = this.data.count;
            let obj = {count:num}
            //利用triggerEvent向父组件传值
            this.triggerEvent("setCount",obj);
        }
    }

})